package com.sql;

import java.sql.*;

public class SqlHelper {
    public static String drivername = "com.mysql.jdbc.Driver";
    public static String username = "amplifi";
    public static String url = "jdbc:mysql://127.0.0.1:1024/ota_service?useUnicode=true&useSSL=false&characterEncoding=utf8";
    public static String password = "AmplifiW0rd!23";

    // test
//    public static String url = "jdbc:mysql://127.0.0.1:3306/ota_service?useUnicode=true&useSSL=false&characterEncoding=utf8";
//    public static String password = "amplifibms";




    public static Connection getConnection() throws ClassNotFoundException, SQLException {
        Class.forName(drivername);
        Connection conn = DriverManager.getConnection(url, username, password);
        return conn;
    }

    public static void close(Connection conn){
        close(conn, null, null);
    }

    public static void close(Connection conn, Statement statement, ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            rs = null;
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            statement = null;
        }

        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            conn = null;
        }
    }



}
